<template>
  <div>
    <el-form :inline="true" class="demo-form-inline" style="text-align: left">
      <el-form-item>
        <el-form-item label="设备名称">
          <el-input
            v-model="formInline.name"
            placeholder="请输入设备名称"
          ></el-input>
        </el-form-item>
        <el-button
          style="background-color: green; color: white"
          icon="el-icon-search"
          @click="list"
          >查询</el-button
        >
        <el-button style="color: gray" icon="el-icon-refresh">重置</el-button>
      </el-form-item>
    </el-form>
    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :row-class-name="tableRowClassName"
      >
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="name" label="设备名称" align="center">
        </el-table-column>
        <el-table-column prop="state" label="日志名称" align="center">
          设备在线
        </el-table-column>
        <el-table-column prop="date" label="发生时间" align="center">
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="countnum"
    >
    </el-pagination>
  </div>
</template>
<script>
import { GetShowDeviceList, GetTotaocount } from "@/api/parkManage/DeviceList";
export default {
  data() {
    return {
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex === 0) {
          return "warning-row";
        } else if (rowIndex === 2) {
          return "success-row";
        }
        return "";
      },
      tableData: [],
      formInline: {
        pageIndex: 1,
        pageSize: 2,
        name: "",
      },
      countnum: 0,
      count: 0,
    };
  },
  created() {
    this.list();
    this.totalcount();
  },
  methods: {
    //显示
    list() {
      GetShowDeviceList(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.formInline.pageIndex = val;
      this.list();
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },
  },
};
</script>
<style>
</style>